cmake_minimum_required(VERSION 2.8)
cmake_policy(VERSION 2.8.0)

project(buola)
enable_testing()

set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules")

include(BuolaMacros)

buola_add_option(BUOLA_WARNINGS_AS_ERRORS "Treat warnings as errors" ON warnings)
buola_add_option(BUOLA_INSTALL_EXAMPLES "Install examples" ON install)

include(BuolaPlatform)
include(BuolaInternal)
include(BuolaDefaults)
include(BuolaInstallDirs)

if(BUOLA_PLATFORM_MAC)
    set(BOOST_COMPONENTS regex thread system chrono)
else()
    set(BOOST_COMPONENTS regex system)
endif()

find_package(Boost 1.50.0 REQUIRED COMPONENTS ${BOOST_COMPONENTS})
find_package(PythonLibs 3.0 REQUIRED)
find_package(Eigen3 REQUIRED)
find_package(Bullet REQUIRED)


include_directories(
            ${CMAKE_SOURCE_DIR}/include
            ${CMAKE_BINARY_DIR}/include
)

include_directories(SYSTEM
            ${PYTHON_INCLUDE_DIRS}
            ${EIGEN3_INCLUDE_DIR}
            ${Boost_INCLUDE_DIRS}
            ${BULLET_INCLUDE_DIRS}
)

if(BUOLA_PLATFORM_MAC)
    include_directories(/usr/local/include /opt/local/include)
endif()

buola_add_option(HAVE_NVIDIA_OPENGL "Have nvidia OpenGL" ON haves)

buola_add_option(BUOLA_USE_INTRINSICS "Use SSE SIMD extensions" ON uses)

buola_add_option(BUOLA_BUILD_DESKTOP "Build desktop applications" ON components)
buola_add_option(BUOLA_BUILD_WEB "Build web browser" OFF components)
buola_add_option(BUOLA_BUILD_BLACKBOX "Build blackbox" ON components)
buola_add_option(BUOLA_BUILD_CV "Build computer vision library" ON components)
buola_add_option(BUOLA_BUILD_MEDIA "Build media library" ON components)
buola_add_option(BUOLA_BUILD_SCENEGRAPH "Build scene graph" ON components)
buola_add_option(BUOLA_BUILD_ROBOT "Build robot components" ON components)

buola_find_optional_packages(BUOLA_HAVE_PULSE PulseAudio)
buola_find_optional_packages(BUOLA_HAVE_FFMPEG FFmpeg)
buola_find_optional_packages(BUOLA_HAVE_OPENNI OpenNI)
buola_find_optional_libraries(LIB_OPENNI2 BUOLA_HAVE_OPENNI2 OpenNI2)
buola_find_optional_libraries(LIB_ICAL BUOLA_HAVE_ICAL ical icalss)
buola_find_optional_libraries(LIB_SDH BUOLA_HAVE_SDH SDHLibrary-CPP)
buola_find_optional_libraries(LIB_TORRENT BUOLA_HAVE_TORRENT torrent-rasterbar)
buola_find_optional_libraries(LIB_DC1394 BUOLA_HAVE_DC1394 dc1394)
buola_find_optional_libraries(LIB_MAD BUOLA_HAVE_MAD mad)
buola_find_optional_libraries(LIB_FREENECT BUOLA_HAVE_FREENECT freenect)
buola_find_optional_packages(BUOLA_HAVE_NAOQI alcommon alvalue alaudio)

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in
                ${CMAKE_CURRENT_BINARY_DIR}/include/buola/config.h)

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/buola/config.h
            DESTINATION ${INCLUDE_INSTALL_DIR}/buola)

configure_file("${CMAKE_CURRENT_SOURCE_DIR}/BuolaConfig.cmake.in"
            "${CMAKE_CURRENT_BINARY_DIR}/BuolaConfig.cmake" @ONLY)

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/BuolaConfig.cmake
        DESTINATION ${SHARE_INSTALL_DIR}/buola)

add_subdirectory(libs)
add_subdirectory(examples)
add_subdirectory(apps)
add_subdirectory(themes)
add_subdirectory(plugins)
add_subdirectory(test)
add_subdirectory(python)
add_subdirectory(include)
add_subdirectory(share)
add_subdirectory(cmake)

buola_print_all_info()
